package com.gl.codewar.template;

import java.util.Iterator;

public class DiamondsAreForever {
	public static String drawDiamond(String string, int i) {
		i = i -1;
		String result ="";
		for (int j = 0; j < i; j++) {
			result += espacionEnBlancoAnteriores(j,i) + string +  espaciosEnElMedio(j,i) + caracterUltimo(j,i,string)+"\n";
		}
		for (int h = i  ; h > -1; --h) {
			result += espacionEnBlancoAnteriores(h,i) + string +  espaciosEnElMedio(h,i) + caracterUltimo(h,i,string)+"\n";
		}
		//StringBuilder reverse = new StringBuilder(result).reverse();	

		return result;
	}

	

	private static String espacionEnBlancoAnteriores(int j, int total) {
		int asdd = total - j;
		String result = "";
		for (int i = 0; i < asdd; i++) {
			result +=  ' ';
			
		}
		return result;
	}

	private static String espaciosEnElMedio(int j, int total) {
		if(j == 0){
			return ""; 
		}
		int imp =  2*j - 1;
		String result = "";
		for (int i = 0; i <  imp ; i++) {
			result +=  ' ';
		}
		return result;
	}
	private static String caracterUltimo(int j, int i, String string) {
		if(j == 0){
			return "";
		}else{
			return string;
		}
	}

}
